﻿using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace ShopPowerTemplate.Common.Authentication
{
    public class CustomEndpointBehavior : IEndpointBehavior
    {
        private IClientMessageInspector _messageInspector;
        private IClientMessageInspector MessageInspector
        {
            get
            {
                if (_messageInspector == null)
                    return new CustomClientMessageInspector();

                return _messageInspector;
            }
            set
            {
                _messageInspector = value;
            }
        }

        public CustomEndpointBehavior()
        {

        }

        public CustomEndpointBehavior(IClientMessageInspector messageInspector)
        {
            MessageInspector = messageInspector;
        }

        public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
        {
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
        {
            clientRuntime.ClientMessageInspectors.Add(MessageInspector);
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
        {
        }

        public void Validate(ServiceEndpoint endpoint)
        {
        }
    }
}
